<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ArrowFunction</title>
</head>
<body>

<script type='text/javascript'>
    "use strict"
    window.onload = function(){
        //无参箭头函数
        /*
        //es6写法
        let fn = ()=> 'zhangjl';
        //解析成es5
        let fn = function(){
            return 'zhangjl';
        }
        */

        //有参数箭头函数
        /*
        let fn = (name) => console.log(name);
        fn('zhangjl');
        */

        /*
        let fn = (name,age) => console.log(name,age);
        fn('张建玲',100);
        */

        //单行箭头函数
        /*let fn = ()=> 'zhangjl';*/

        //多行箭头函数
        /*
        let fn = (name,age) => {
            console.log(name);
            console.log(age);
        }
        fn('张建玲',100);
        */

        //多层嵌套
        /*
        let fn1 = name => ({
            getName:() => {
                console.log(name);
            }
        })
        fn1('zhangjl').getName();
        */

        //--------------------箭头函数this-------------------
        /*
        let base = {
            num : 5,
            fn(){
                return () => {
                    return () => {
                        console.log(this.num);
                    }
                }
            }
        };
        base.fn()()();
        */

        let base = {
            baseUrl : 'http://localhost:8080/app',
            fn(param){
               return fetch(`${this.baseUrl}/getUserId?p=${param}`)
                   .then(res => res.json)
                   .then(rows => fetch(`${this.baseUrl}/getUser?p=${rows.join(',')}`))
                   .then(res => res.json);
            }
        }
    }
</script>
</body>
</html>